import '../model/result_model.dart';
import '../model/test_batch_exam_model.dart';
import '../utils/request.dart';

///考试接口
class TestBatchExamApi {
  TestBatchExamApi._();

  static final _singleton = TestBatchExamApi._();

  factory TestBatchExamApi() => _singleton;

  ///查询
  Future<TestBatchExamQueryRes> query(TestBatchExamQueryReq req) => request
      .getHandler(
        path: '/test-batch/${req.batchId}/exam',
        params: req.toMap(),
      )
      .then((res) => TestBatchExamQueryRes.fromModel(res));

  ///加载
  Future<TestBatchExamInfoRes> info(final String id) => request
      .getHandler(path: '/test-batch/exam/$id')
      .then((res) => TestBatchExamInfoRes.fromModel(res));

  ///新增
  Future<BaseModelRes> add(final TestBatchExamAddReq req) => request
      .postHandler(path: '/test-batch/${req.batchId}/exam', data: req.toMap());

  ///修改
  Future<BaseModelRes> modify(final TestBatchExamModifyReq req) =>
      request.putHandler(path: '/test-batch/exam/${req.id}', data: req.toMap());

  ///删除
  Future<BaseModelRes> delete(final String id) =>
      request.deleteHandler(path: '/test-batch/exam/$id');
}

///考试接口单例
final testBatchExamApi = TestBatchExamApi();
